<?php

/**
 * alltosun.com 终端设备控制器 index.php
 * ============================================================================
 * 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 刘德洪 (Liudh@alltosun.com) $
 * $Date: 20151124 $
 * $Id$
 */
class Action
{
    private $per_page = 100;

    /**
     * 显示列表
     */
    public function index()
    {
        $page          = Request::Get('page_no', 1);
        $status        = Request::getParam('status', -1);
        $search_filter = Request::getParam('search_filter', array());

        // 拼装搜索条件
        $is_empty = 0;
        $filter = array();

        if (isset($search_filter['id']) && $search_filter['id']) {
            $filter['id'] = $search_filter['id'];
        }

        if (isset($search_filter['machine_no']) && $search_filter['machine_no']) {
            $filter['machine_no'] = $search_filter['machine_no'];
        }
        
        if (-1 != $status) {
            $filter['status'] = $status;
        } else {
            $filter['status'] = array(0, 1, 2, 3);
        }
        

        $machine_list = array();
        $machine_list = get_data_list('machine', $filter, 'ORDER BY id DESC', $page);

        Response::assign('machine_list', $machine_list);
        Response::assign('status', $status);
        Response::assign('search_filter', $search_filter);

        Response::display('admin/machine_list.html');
    }

    /**
     * 修改状态
     */
    public function change_status()
    {
        $id = Request::getParam('id', 0);
        $status = Request::getParam('status', -1);
        if (!$id) {
            return '请选择要更改的内容';
        }

        $info = _uri('store_machine', $id);
        if ($status == $info['status']) {
            return '已经执行过此操作，不用重复提交';
        }

        _model('store_machine')->update($id, array('status' => $status));

        return 'ok';
    }
    
    
    /**
     * 获取设备好记录列表
     */
    public function get_device_no_record()
    {
        $id = Request::getParam('id', 0);
        $device_no = Request::getParam('device_no', '');
        if (!$id || !$device_no) {
        	return array('没有设备id或设备号','error', AnUrl('machine/admin'));
        }
        
        $record_list = array();
        $record_list = _widget('store')->get_device_no_record($id, $device_no);
        
        Response::assign('record_list', $record_list);
        Response::assign('device_no', $device_no);
        Response::display('admin/device_no_record.html');
        
    }
    
}
